<template>
    <div class="user-create-template">
        <el-button class="return" type="text" @click="jumpToDefault"><i class="fa fa-angle-left mr5"></i>返回</el-button>
        <h4 class="header">创建用户资料信息</h4>
        <div class="content">
            <div class="filter-section">
                <span class="fl title">管理用户基本信息</span>
                <span class="fr gray">注：带有*为必填项</span>
            </div>
            <div class="user-form">
                <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
                    <el-form-item label="用户名" prop="username">
                        <el-input v-model="ruleForm.username" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="部门名称" prop="department">
                        <el-select v-model="ruleForm.department" placeholder="请选择部门名称" size="mini">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="密码" prop="password">
                        <el-input v-model="ruleForm.password" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="职位名称" prop="jobName">
                        <el-input v-model="ruleForm.jobName" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="员工姓名" prop="employeeName">
                        <el-input v-model="ruleForm.employeeName" size="mini"></el-input>
                    </el-form-item>
                    <el-form-item label="职务类别" prop="jobCategory">
                        <el-select v-model="ruleForm.jobCategory" placeholder="请选择职务类别" size="mini">
                            <el-option label="区域一" value="shanghai"></el-option>
                            <el-option label="区域二" value="beijing"></el-option>
                        </el-select>
                    </el-form-item>
                    <div class="btn-wrap">
                        <el-button type="primary" @click="submitForm('ruleForm')">确定保存</el-button>
                        <el-button @click="cancelForm()">取消</el-button>
                    </div>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "UserCreate",
        data() {
            return {
                ruleForm: {
                    username: "",
                    department: "",
                    password: "",
                    jobName: "",
                    employeeName: "",
                    jobCategory: ""
                },
                rules: {
                    username: [
                        {required: true, message: '请输入用户名', trigger: 'blur'}
                    ],
                    department: [
                        {required: true, message: '请选择部门名称', trigger: 'change'},
                    ],
                    password: [
                        {required: true, message: '请输入密码', trigger: 'blur'}
                    ],
                    employeeName: [
                        {required: true, message: '请输入员工姓名', trigger: 'blur'}
                    ],
                    jobCategory: [
                        {required: true, message: '请选择职务类别', trigger: 'change'},
                    ]
                }
            }
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        console.log('submit!');
                        this.jumpToDefault();
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            cancelForm() {
                this.jumpToDefault();
            },
            jumpToDefault() {
                this.$parent.curPath = 'default';
            }
        }
    }
</script>

<style lang="scss">
    @import "src/common/common.style";
    .user-create-template {
        background-color: #ffffff;
        width: 100%;
        height: 100%;
        position: relative;
        .return {
            position: absolute;
            top: 0;
            left: 15px;
            padding: 0;
        }
        .header {
            text-align: center;
        }
        .content {
            height: 100%;
            .filter-section {
                border-bottom: 1px solid #ddd;
                padding-bottom: 25px;
                margin: 0 10px;
                padding-left: 5px;
                padding-right: 5px;
                .title {
                    font-size: $font-mn;
                    font-weight: 600;
                }
                .gray {
                    color: gray;
                }
            }
            .user-form {
                height: 100%;
                padding-top: 10px;
                .el-form {
                    height: calc(100% - 120px);
                    @include ofy-a();
                    margin: 0 50px;
                    .el-form-item {
                        margin-bottom: 15px;
                        display: inline-block;
                        width: 50%;
                        .el-form-item__content {
                            @include fl();
                            margin-left: 0 !important;
                        }
                        .el-input {
                            width: 300px;
                        }
                    }
                    .btn-wrap {
                        margin-top: 50px;
                        .el-button {
                            width: 100px;
                            margin: 0 50px;
                        }
                    }
                }
            }
        }
    }
</style>